package javaweb_work01.main.Dao;

import javaweb_work01.login.Utils.DruidUtils;
import javaweb_work01.main.Entity.Students;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * 访问数据库实现修改指定学号的学员信息
 */
public class SetStudentsDaoImp implements SetStudentsDao{
    @Override
    public void setStudents(Students students) {
        try {
            //使用连接池创建QueryRunner对象
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            //编写sql语句
            String sql = "update students set name = ?, sex = ?, date = ?, email = ?, remark = ? where num = ?";
            //设置占位符参数
            Object[] param = {students.getName(),students.getSex(),students.getDate(),students.getEmail(),students.getRemark(),students.getNum()};
            //执行语句
            int update = qr.update(sql, param);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
